package image_test;
import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Image_test {
	Shell m_shell;
	Display m_display;
	Canvas m_canvas;
	String m_lastPath;
	static final String[] OPEN_FILTER_EXTENSIONS = new String[] {		
		"*.*",
		"*.bmp; *.gif; *.ico; *.jfif; *.jpeg; *.jpg; *.png; *.tif; *.tiff",
		"*.bmp", "*.gif", "*.ico", "*.jpg; *.jpeg; *.jfif",
		"*.png", "*.tif; *.tiff" };
	static final String[] OPEN_FILTER_NAMES = new String[] {
		//bundle.getString("All_images") + 		
		//			
		"All Files (*.*)", 
		"All images" + " (*.bmp, *.gif, *.ico, *.jfif, *.jpeg, *.jpg, *.png, *.tif, *.tiff)",
		"BMP (*.bmp)", "GIF (*.gif)", "ICO (*.ico)", "JPEG (*.jpg, *.jpeg, *.jfif)",
		"PNG (*.png)", "TIFF (*.tif, *.tiff)"};
	static final String[] SAVE_FILTER_EXTENSIONS = new String[] {
		"*.bmp", "*.bmp", "*.gif", "*.ico", "*.jpg", "*.png", "*.tif", "*.bmp" };
	static final String[] SAVE_FILTER_NAMES = new String[] {
		"Uncompressed BMP (*.bmp)", "RLE Compressed BMP (*.bmp)", "GIF (*.gif)",
		"ICO (*.ico)", "JPEG (*.jpg)", "PNG (*.png)",
		"TIFF (*.tif)", "OS/2 BMP (*.bmp)" };
	public void go(){
		String title = "Title";
		m_display = new Display();
		m_shell= new Shell(m_display,SWT.CLOSE|SWT.RESIZE);
		m_shell.setText(title);
		m_shell.setSize(500, 500);
		create_menu();
		m_shell.open();
		while(!m_display.isDisposed()){
			if(!m_display.readAndDispatch()){
				m_display.sleep();
			}
		}
		m_shell.dispose();
		
	}
	protected void create_menu(){
		Menu menuBar= new Menu(m_shell,SWT.BAR);
		m_shell.setMenuBar(menuBar);
		MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
		item.setText("File");
		Menu fileMenu = new Menu(m_shell,SWT.DROP_DOWN);
		item.setMenu(fileMenu);
		
		
		//File-open
		item = new MenuItem(fileMenu,SWT.PUSH);
		item.setText("Open");
		item.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent event){
				open_file();
			}
		});			
		//File-exit
		item = new MenuItem(fileMenu,SWT.PUSH);
		item.setText("Exit");
		item.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent event){
				exit_app();
			}
		});			
	}
	public int open_file(){
		FileDialog fileChooser = new FileDialog(m_shell, SWT.OPEN);
		if (m_lastPath != null)
			fileChooser.setFilterPath(m_lastPath);
		fileChooser.setFilterExtensions(OPEN_FILTER_EXTENSIONS);
		fileChooser.setFilterNames(OPEN_FILTER_NAMES);
		String filename = fileChooser.open();
		m_lastPath = fileChooser.getFilterPath();
		if (filename == null)
			return 0;		
		System.out.println(filename);
		return 1;		
	}
	public void create_controls(){
		Color whiteColor = null, blackColor, redColor, greenColor, blueColor, canvasBackground;
		Font fixedWidthFont;
		Cursor crossCursor = null;		
		m_canvas = new Canvas(m_shell,SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
		
		m_canvas.setBackground(whiteColor);
		m_canvas.setCursor(crossCursor);
		GridData gridData = new GridData();
		gridData.verticalSpan = 15;
		gridData.horizontalAlignment = GridData.FILL;
		gridData.verticalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		m_canvas.setLayoutData(gridData);		
		
	}
	public void exit_app(){
		System.exit(0);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Image_test test = new Image_test();
		test.go();
	}

}
